<?php
  error_reporting(E_ALL ^ (E_NOTICE | E_USER_NOTICE | E_STRICT));

  // stub for binaries
  if (!$_SERVER['DOCUMENT_ROOT']) {
    $path = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
    array_pop($path);
    $_SERVER['DOCUMENT_ROOT'] = implode(DIRECTORY_SEPARATOR, $path);
  }

  // root path autodetection
  $path_array = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
  
  $path = implode(DIRECTORY_SEPARATOR, $path_array);

  //основные пути
  define('CFG_PATH_ROOT',       $path); // Но можно задать и вручную
  define('CFG_PATH_HTDOCS',     CFG_PATH_ROOT/*.DIRECTORY_SEPARATOR.'docs'*/);
  
  define('CFG_PATH_CLASSES',    CFG_PATH_HTDOCS.DIRECTORY_SEPARATOR.'classes');
  define('CFG_PATH_WORKER',     CFG_PATH_CLASSES.DIRECTORY_SEPARATOR.'Worker');
  define('CFG_PATH_SOCIAL',     CFG_PATH_CLASSES.DIRECTORY_SEPARATOR.'Social');
  define('CFG_MODELS_CLASSES',  CFG_PATH_HTDOCS.DIRECTORY_SEPARATOR.'models');
  define('CFG_CONTROL_CLASSES', CFG_PATH_HTDOCS.DIRECTORY_SEPARATOR.'controllers');
  define('CFG_BATTLE_CLASSES',  CFG_PATH_HTDOCS.DIRECTORY_SEPARATOR.'battle');
  
  //параметры почты
  define('CFG_MAIL_FROM', 		'rodion89@list.ru');
  define('CFG_MAIL_EXEPTION', 	'rodion89@list.ru');
  define('CFG_MAIL_BCC', 		'rodion89@list.ru');


  
  if (!empty($_SERVER['HTTP_HOST'])) {
    $domain_array = explode(".", $_SERVER['HTTP_HOST']);
    if (count($domain_array) > 2) array_shift($domain_array);
    $domain = implode(".", $domain_array);
  } 
  
  if(strpos($_SERVER['HTTP_HOST'], "wizardjiocb")){
 	 define('CFG_HOST_IMG',        'http://www.wizardjiocb.ru/images/');
  }else{
  	 define('CFG_HOST_IMG',        "http://".$_SERVER['HTTP_HOST']."/images/");
  }

  // Отладочные хрени
  define('DEBUG_AUTOLOAD', false); 
  define('DEBUG_ERRORS_TO_FILE', true);   

  // initialization code
  date_default_timezone_set('Europe/Moscow');

  /**
   * настройка автоматической загрузки файлов с требуемыми классами
   *
   * @param string $class_name
   * @link http://php.net/manual/en/language.oop5.autoload.php
   */
  function __autoload($class_name) {
    $autoload_rules = array();
    
    $autoload_rules[] = CFG_PATH_CLASSES . DIRECTORY_SEPARATOR . $class_name . '.php';
    $autoload_rules[] = CFG_MODELS_CLASSES . DIRECTORY_SEPARATOR . $class_name . ".php";
    $autoload_rules[] = CFG_PATH_WORKER . DIRECTORY_SEPARATOR . $class_name . ".php";
    $autoload_rules[] = CFG_BATTLE_CLASSES . DIRECTORY_SEPARATOR . $class_name . ".php";
    $autoload_rules[] = CFG_PATH_SOCIAL . DIRECTORY_SEPARATOR . $class_name . ".php";

    $a = explode('_', $class_name);
    $autoload_rules[] = CFG_PATH_CLASSES . DIRECTORY_SEPARATOR . array_shift($a) . DIRECTORY_SEPARATOR . $class_name . '.php';

    
    // try to load class
    foreach($autoload_rules as $class_file) {
      if (defined('DEBUG_AUTOLOAD') && DEBUG_AUTOLOAD) echo("testing $class_name vs [$class_file]<br>");
      if (file_exists($class_file)) {
        require_once $class_file;
        if (defined('DEBUG_AUTOLOAD') && DEBUG_AUTOLOAD) echo("&nbsp;&nbsp;::&nbsp;loaded $class_name from [$class_file]<br>");
        return;
      }
    }
    trigger_error("__autoload failed: class [$class_name] was not found!");
  }

  
  	
  	define("DB_TYPE","pgsql");
    define("DB_HOST","78.110.60.209");
    define("DB_PORT","5432");
    define("DB_USER","postgres");
    define("DB_PASS","44aPrGg6");
    define("DB_NAME","WJ");
    
    define("RPL_HOST", "rpl.wizardjiocb.ru");
    define("RPL_PORT", "10010");
    define("RPL_NAMESPACE", "test_ava");
    
    define("MC_HOST","localhost");
    define("MC_PORT","11211");
  
  function json_fix_cyr($json_str) {
		$cyr_chars = array (
		'\u0430' => 'а', '\u0410' => 'А',
		'\u0431' => 'б', '\u0411' => 'Б',
		'\u0432' => 'в', '\u0412' => 'В',
		'\u0433' => 'г', '\u0413' => 'Г',
		'\u0434' => 'д', '\u0414' => 'Д',
		'\u0435' => 'е', '\u0415' => 'Е',
		'\u0451' => 'ё', '\u0401' => 'Ё',
		'\u0436' => 'ж', '\u0416' => 'Ж',
		'\u0437' => 'з', '\u0417' => 'З',
		'\u0438' => 'и', '\u0418' => 'И',
		'\u0439' => 'й', '\u0419' => 'Й',
		'\u043a' => 'к', '\u041a' => 'К',
		'\u043b' => 'л', '\u041b' => 'Л',
		'\u043c' => 'м', '\u041c' => 'М',
		'\u043d' => 'н', '\u041d' => 'Н',
		'\u043e' => 'о', '\u041e' => 'О',
		'\u043f' => 'п', '\u041f' => 'П',
		'\u0440' => 'р', '\u0420' => 'Р',
		'\u0441' => 'с', '\u0421' => 'С',
		'\u0442' => 'т', '\u0422' => 'Т',
		'\u0443' => 'у', '\u0423' => 'У',
		'\u0444' => 'ф', '\u0424' => 'Ф',
		'\u0445' => 'х', '\u0425' => 'Х',
		'\u0446' => 'ц', '\u0426' => 'Ц',
		'\u0447' => 'ч', '\u0427' => 'Ч',
		'\u0448' => 'ш', '\u0428' => 'Ш',
		'\u0449' => 'щ', '\u0429' => 'Щ',
		'\u044a' => 'ъ', '\u042a' => 'Ъ',
		'\u044b' => 'ы', '\u042b' => 'Ы',
		'\u044c' => 'ь', '\u042c' => 'Ь',
		'\u044d' => 'э', '\u042d' => 'Э',
		'\u044e' => 'ю', '\u042e' => 'Ю',
		'\u044f' => 'я', '\u042f' => 'Я',

		'\r' => '',
		'\n' => '<br />',
		'\t' => ''
		);

		foreach ($cyr_chars as $cyr_char_key => $cyr_char) {
			$json_str = str_replace($cyr_char_key, $cyr_char, $json_str);
		}
		return $json_str;
	}
  
?>